package com.ihr360.payroll.controller.admin;

import com.ihr360.excel.view.ExcelSheetDef;
import com.ihr360.excel.view.ExcelView;
import com.ihr360.maven.plugin.ModuleCodeStore;
import com.ihr360.maven.plugin.annotation.FunctionDefinition;
import com.ihr360.maven.plugin.annotation.ModuleDefinition;
import com.ihr360.payroll.service.salarytasklet.SalaryCalcMiddleDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/admin/salary/calc/middledata/")
@ModuleDefinition(mainModuleCode = ModuleCodeStore.Module.SALARY_CODE_ADMIN,
        mainModuleName = ModuleCodeStore.Module.SALARY_NAME_ADMIN,
        subModuleCode = ModuleCodeStore.Module.SalaryAdmin.BATCH_JOB_EXECUTION_CODE,
        subModuleName = ModuleCodeStore.Module.SalaryAdmin.BATCH_JOB_EXECUTION_NAME)
public class SalaryCalcMiddleDataController {

    @Autowired
    private SalaryCalcMiddleDataService salaryCalcMiddleDataService;

    @FunctionDefinition(functionName = "将某个批次的执行数据转换为Excel", functionCode = ModuleCodeStore.Function.VIEW)
    @RequestMapping(value = "/report/{termId}.xls", method = RequestMethod.GET)
    public ModelAndView csvReport(@PathVariable(name = "termId") Long termId, Model model) {
        ExcelSheetDef<String> excelSheet = salaryCalcMiddleDataService.loadMiddleToSheet(termId);
        if (excelSheet!=null) {
            model.addAttribute(ExcelView.MODEL_KEY, excelSheet);
        }
        return new ModelAndView("");
    }
}